package com.moqbus.service.db.mysql.dao;

import java.math.BigInteger;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import com.moqbus.service.db.mysql.ConnectionPool;
import com.moqbus.service.db.mysql.bean.CmdEncodeEntity;
import com.moqbus.service.db.mysql.bean.LastDataEntity;

public class CmdEncodeDao extends BaseDao {

	public CmdEncodeDao(Connection _conn) {
		super(_conn);
	}
	
	static Connection conn() {
		return ConnectionPool.getInstance();
	}
	
	public static CmdEncodeEntity findBySnoCmdNo(Integer deviceId, Integer sensorNo, Integer cmdNo) {

		try {
	        //创建SQL执行工具   
	        QueryRunner qRunner = new QueryRunner();  
	        
			String sql = "select c.* from t_sensor s";
			sql += " left join t_cmd_encode c";
			sql += " on s.id = c.sensorId";
			sql += " where s.deviceId = ?";
			sql += " and s.sensorNo = ?";
			sql += " and c.cmdNo = ?";

			BeanHandler<CmdEncodeEntity> bh = new BeanHandler<CmdEncodeEntity>(CmdEncodeEntity.class);
			 
			CmdEncodeEntity bean = (CmdEncodeEntity) qRunner.query(conn(), sql, bh, deviceId, sensorNo, cmdNo);
	        
	        return bean;
	        
		} catch (SQLException e) {
			
			LOG.error("", e);
			return null;
		} 
	}

}
